package com.uidt.common.utils;

import cn.hutool.core.util.IdUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson2.JSONObject;
import com.uidt.project.ptsj.domain.Inspection;

import java.util.Date;

import static com.uidt.common.utils.sign.SignUtil.createSign;

public class SignUtil {


    public static void main(String[] args) {
        String jsonstr ="{\"roomId\":\"3309021721541426551\",\"placeId\":\"74059\",\"placeName\":\"传奇庄园民宿\",\"roomNumber\":\"105\",\"scoreList\":[{\"scoreType\":1,\"score\":0}],\"problemList\":[{\"problemContent\":\"\"}],\"cardType\":\"3\",\"cardItem\":\"1\",\"rectStartTime\":\"2024-08-15T16:00:00.000Z\",\"rectEndTime\":\"2024-08-29T16:00:00.000Z\"}";
        JSONObject inspection = JSONObject.parseObject(jsonstr);
        Date date = inspection.getDate("rectStartTime");
        Inspection ptsjInspection = new Inspection();
        ptsjInspection.setInspectionTime(DateUtils.getNowDate());
        ptsjInspection.setCreatedTime(DateUtils.getNowDate());
        ptsjInspection.setRoomName(inspection.getString("placeName"));
        ptsjInspection.setRoomProblem(inspection.getString("roomProblem"));
        ptsjInspection.setRectStartTime(inspection.getDate("rectStartTime"));
        ptsjInspection.setRectEndTime(inspection.getDate("rectEndTime"));
        System.out.println(date);
        System.out.println(DateUtils.getNowDate());
        System.out.println(DateUtils.parseDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,date)));
        System.out.println(ptsjInspection.toString());
    }

    public static void ptsj(){
        String baseUrl = "https://zsgawyf.police.zhoushan.gov.cn:17000/webapi";
        String api = "/olp/shgz/v1/queryFy";
        String url = baseUrl + api;
        String clientId = "6888bc08296546ec9c8a869b0973daae";
        String secretKey = "ac4e9a7c56db447ab1732f6ec2902925";
        String sm4key = "3b19ab2ce6f54bc3bf0926f9e8406154";
        String salt = IdUtil.simpleUUID();
        String now = "" + System.currentTimeMillis();
        JSONObject signParams = new JSONObject();
        signParams.put("clientId", clientId);
        signParams.put("timestamp", now);
        signParams.put("salt",salt);
        String sign = createSign(signParams.toJSONString(),secretKey);
        System.out.println("clientId:\t" + clientId + "\n"
                +"timestamp:\t" + now + "\n"
                +"salt:\t" + salt + "\n"
                +"sign:\t" + sign);
        JSONObject params = new JSONObject();
        params.put("start", 1);
        params.put("limit", 10);
        HttpResponse execute = HttpRequest.post(url)
                .header("sign", sign)
                .header("jsonStr", signParams.toJSONString())
                //请求参数
                .body(params.toString())
                .execute();
        String body = execute.body();
        System.out.println(body);
    }












}
